package com.tushu.dao;

import com.tushu.model.Dto;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class LentBookDao extends BaseDAO {

    public  List<Dto> findAll() {
        String sql = "SELECT\n" +
                "\tb.isbn,\n" +
                "\tb.book_name,\n" +
                "\ts.`name`,\n" +
                "\ts.account ,\n" +
                "\tl.lend_time,\n" +
                "\tl.return_time\n" +
                "FROM\n" +
                "\ttb_lend l\n" +
                "\tLEFT JOIN tb_book b ON l.book_id = b.id\n" +
                "\tLEFT JOIN tb_student s ON l.student_id = s.id ";
        return super.selectAll(sql, new Object[]{});
    }

    @Override
    public Dto rowMapper(ResultSet rs) throws SQLException {
        Dto dto = new Dto();
        dto.setIsbn(rs.getString("isbn"));
        dto.setBookName(rs.getString("book_name"));
        dto.setStudentName(rs.getString("name"));
        dto.setStudentAccount(rs.getString("account"));
        dto.setLendTime(rs.getString("lend_time"));
        dto.setReturnTime(rs.getString("return_time"));
        return dto;
    }
}

